import { firstMenu, mapAllRouter, mapMenuToRoutes } from '@/utils/map-menus'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/main'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/login.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('@/views/main/main.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/not-found/not-found.vue')
  }
]
const router = createRouter({
  history: createWebHashHistory(),
  routes: routes
})
// 动态获取路由的所有信息(参考工具函数utils map-menus.ts)
// const addAllRouter = mapAllRouter()
// addAllRouter.forEach((route) => router.addRoute('main', route))
router.beforeEach((to, from) => {
  if (to.path === '/main') {
    return firstMenu.url
  }
})
export default router
